#include <jni.h>
#include <string>
#include <android/log.h>
#include "client/linux/handler/minidump_descriptor.h"
#include "client/linux/handler/exception_handler.h"

extern "C" JNIEXPORT jstring
JNICALL
Java_com_cms_breakpad_NativeLib_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}
bool DumpCallback(const google_breakpad::MinidumpDescriptor &descriptor,
                  void *context,
                  bool succeeded) {
    __android_log_print(ANDROID_LOG_ERROR, "native", "native crash:%s", descriptor.path());
    return false;
}
extern "C"
JNIEXPORT void
JNICALL
Java_com_cms_breakpad_NativeLib_initBreakpad(
        JNIEnv * env,
        jobject,
        jstring path_){
const char *path = env->GetStringUTFChars(path_, 0);

__android_log_print(ANDROID_LOG_INFO, "native", "===> %s", path);
google_breakpad::MinidumpDescriptor descriptor(path);
static google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback,
                                            NULL, true, -1);

env->ReleaseStringUTFChars(path_, path);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_cms_breakpad_NativeLib_testNativeCrash(JNIEnv *env, jobject clazz) {

__android_log_print(ANDROID_LOG_INFO, "native", "xxxxxxxxxx");

int *p = NULL;
*p = 10;

}

